package com.example.permission.myjbm.model;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.permission.myjbm.activitys.IntegralCenterAty;
import com.example.permission.myjbm.activitys.IntegralDetail;
import com.example.permission.myjbm.dao.BaseObj;
import com.example.permission.myjbm.net.ReleaseNet;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.jbm.jbmsupplier.util.ExProductEntity;

import java.util.List;

/**
 * 积分中心Model
 * Created by JBMhaier on 2017/3/14.
 */

public class IntegralModel extends BaseObj{
private Context c;
    private int page;
    private ReleaseNet net;
    public IntegralModel(TextView headerRight, TextView headerTitle, String title, Context c, ReleaseNet net) {
        super(headerRight, headerTitle, title, null);
        page=0;
        this.net=net;
        this.c=c;
    }
    //item点击事件
    public void itemClick(GridView integralJifenCollect, final List<ExProductEntity> prodectList){
        integralJifenCollect.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    //跳转
                //TODO 积分详情页   兑换
                Intent intent=new Intent(c, IntegralDetail.class);
                intent.putExtra("isDetial",0);
                intent.putExtra("exp_id",prodectList.get(position).getExpId());
                ((IntegralCenterAty)c).startActivityForResult(intent,100);

            }
        });
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    /**
     * pull的上拉和下拉
     * @param pull
     */
    public void setPull(PullToRefreshListView pull){
        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                    page=0;
             net.getJifenMingxi(page);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                    page+=10;
                net.getJifenMingxi(page);
            }
        });
        pull.setOnLastItemVisibleListener(new PullToRefreshBase.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {
                page+=10;
                net.getJifenMingxi(page);
            }
        });

    }

}
